using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Universal.Application.Contracts.Common;
using Universal.Application.Contracts.Dto.User;
using Universal.Application.Repositories;

namespace Universal.Api.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class FileController : ControllerBase
{
    private readonly IFileService _fileService;
    public FileController(IFileService fileService)
    {
        _fileService = fileService;
    }

    [HttpPost("upload-avatar")]
    public async Task<IActionResult> UploadAvatar([FromForm] UploadAvatarDto dto)
    {
        if (dto.File == null || dto.File.Length == 0)
            return Ok(ApiResponse<string>.Failure(400, "请选择要上传的文件"));

        if (string.IsNullOrEmpty(dto.UserId))
            return Ok(ApiResponse<string>.Failure(400, "用户ID不能为空"));

        // Console.WriteLine($"收到上传请求，UserId={dto.UserId}, FileName={dto.File?.FileName}");
        var result = await _fileService.UploadAvatarAsync(dto);
        return Ok(result);
    }

}